layui.use(['form','treeSelect','layer','upload','laydate','layedit','tableSelect'],function(){
    var form = layui.form
        layer = parent.layer === undefined ? layui.layer : top.layer,
        $ = layui.jquery;


    //监听仪器是否可用开关
    form.on('switch(switchTest)', function(data){
        if (this.checked) {
            $("#status").val('0');
            tempStatus = "0";
            console.log(0);
        } else {
            $("#status").val('1');
            tempStatus = "1";
            console.log(1);
        }
    });

    //回显数据
    var request = GetRequest();



    let tempStatus = "0";
    //监听仪器是否可用开关
    form.on('switch(switchTest)', function(data){
        if (this.checked) {
            $("#status").val('0');
            tempStatus = "0";
            console.log(0);
        } else {
            $("#status").val('1');
            tempStatus = "1";
            console.log(1);
        }
    });

    form.on("submit(edit)",function(data){

        var index = top.layer.msg('数据提交中，请稍候',{icon: 16,time:false,shade:0.8});
        $.post("/admin/facilityUsed/edit",{
            id:request.id,
            facilityId:request.facilityId,
            afterStatus:tempStatus,
            returnback:true
        },function(res){
            if(res.code!=200)
            {
                top.layer.msg("归还失败！");
                return false;
            }else{
                top.layer.close(index);
                top.layer.msg("归还成功！");
                layer.closeAll("iframe");
                //刷新父页面
                parent.location.reload();
            }
        })

        return false;
    })


    //获取路径中的参数
    function GetRequest() {
        var url = location.search;         //获取url中"?"符后的字串
        var theRequest = new Object();
        if (url.indexOf("?") != -1) {
            var str = url.substr(1);
            var strs = str.split("&");
            for (var i = 0; i < strs.length; i++) {
                theRequest[strs[i].split("=")[0]] = decodeURIComponent(strs[i].split("=")[1]);
            }
        }
        return theRequest;
    }


});